package com.example.service.impl;

import com.example.mapper.MaterialMapper;
import com.example.mapper.PayMapper;
import com.example.mapper.PlanMapper;
import com.example.pojo.Emp;
import com.example.pojo.PageBean;
import com.example.pojo.Plan;
import com.example.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class PlanServiceImpl implements PlanService {
    @Autowired
    private PlanMapper planMapper;
    @Autowired
    private PayMapper payMapper;
    @Autowired
    private MaterialMapper materialMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize, String planName, int departmentID, LocalDate begin, LocalDate end) {
        Long count = planMapper.count(planName, departmentID, begin, end);//总数返回
        Integer start = (page - 1) * pageSize;//计算起始位置
        List<Plan> empList = planMapper.page(start, pageSize, planName, departmentID, begin, end);//该页记录数返回

        PageBean pageBean = new PageBean(count, empList);
        return pageBean;
    }

    @Override
    public void add(Plan plan) {
        planMapper.add(plan);
        payMapper.update(plan.getPayid());
    }

    @Override
    public void delete(List<Integer> ids) {
        planMapper.delete(ids);
    }

    @Override
    public void update(Plan plan) {
        planMapper.update(plan);
    }

    @Override
    public List<Plan> getAll() {
        return planMapper.getAll();
    }
}
